<template>
  <view class="custom-tab-bar" :class="{ 'order-active': active === 1 }">
    <view class="tab-item" :class="{ active: active === 0 }" @click="switchTab(0, '/pages/index/index')">
      <image :src="active === 0 ? '/static/images/tabbar/home_.png' : '/static/images/tabbar/home.png'" class="tab-icon"></image>
      <text class="tab-text">首页</text>
    </view>
    
    <view class="tab-item center-item">
      <view class="center-btn" :class="{ active: active === 1 }" @click="switchTab(1, '/pages/index/work')">
        <text>订单</text>
      </view>
    </view>
    
    <view class="tab-item" :class="{ active: active === 2 }" @click="switchTab(2, '/pages/index/mine')">
      <image :src="active === 2 ? '/static/images/tabbar/mine_.png' : '/static/images/tabbar/mine.png'" class="tab-icon"></image>
      <text class="tab-text">我的</text>
    </view>
  </view>
</template>

<script>
export default {
  name: 'CustomTabbar',
  props: {
    active: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      
    }
  },
  methods: {
    switchTab(index, url) {

      console.log('当前激活的tab：', index);

      if (index === 1) {
         uni.removeStorageSync('workDefaultTab');
         
      }

      if (this.active !== index) {
        // 对于中间按钮，使用switchTab而不是navigateTo
        uni.switchTab({
          url
        });
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.custom-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100rpx;
  background-color: #ffffff;
  display: flex;
  box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  z-index: 999;
  padding-bottom: env(safe-area-inset-bottom); /* 适配底部安全区域 */
}

/* 当订单按钮激活时，确保其他按钮不受影响 */
.custom-tab-bar.order-active .tab-item:not(.center-item) {
  transform: scale(1); /* 保持原始大小 */
  height: 100rpx;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100rpx;
  transform-origin: center center;
  transition: transform 0.2s ease;
}

.tab-item.active .tab-text {
  color: #2196f3;
}

.center-item {
  position: relative;
  height: 100rpx;
  display: flex;
  align-items: center; /* 确保居中对齐 */
  justify-content: center;
}

.center-btn {
  position: absolute;
  width: 120rpx;
  height: 120rpx;
  background-color: #003399; /* 深蓝色，与图片一致 */
  border-radius: 50%;
  /* 定位方式，确保完全居中 */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -70%); /* 水平居中，并向上偏移，保持凸起效果 */
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 32rpx;
  font-weight: bold;
  box-shadow: 0 4rpx 16rpx rgba(0, 51, 153, 0.4); /* 阴影效果 */
  transition: all 0.2s ease;
  z-index: 1000; /* 确保按钮在最上层 */
}

/* 添加选中状态样式 */
.center-btn.active {
  background-color: #002266; /* 更深的蓝色 */
  box-shadow: 0 6rpx 20rpx rgba(0, 51, 153, 0.6); /* 更强的阴影 */
}

/* 添加按下效果 */
.center-btn:active {
  transform: translate(-50%, -65%); /* 按下时稍微上移减少 */
  box-shadow: 0 2rpx 8rpx rgba(0, 51, 153, 0.3);
}

/* 确保图标大小固定 */
.tab-icon {
  width: 48rpx;
  height: 48rpx;
  margin-bottom: 6rpx;
}

/* 确保文字大小固定 */
.tab-text {
  font-size: 24rpx;
  color: #999999;
  transform: scale(1); /* 保持原始大小 */
}
</style>